﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSqlServer;

public partial class system_infoclass : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
        }
        else
        {
            TEmployee.CheckUser(this);
            
            btnNew.Attributes.Add("OnClick", "javascript:return chk();");
            btnEdit.Attributes.Add("OnClick", "javascript:return chk();");

            ListInfo1();
        }
    }
    private void ListInfo1()
    {
        string sSql = "select typeid,typename from t_sys_info1 order by orderby";
        TSqlDBReader myReader = new TSqlDBReader(sSql);
        dlRS.DataSource = myReader.FDataReader;
        dlRS.DataBind();
        //关闭
        myReader.Free();
    }
    protected void dlRS_ItemCommand(object source, DataListCommandEventArgs e)
    {
        LinkButton b = (LinkButton)e.CommandSource;
        switch (b.CommandName)
        {
            case "modify":
                TSysInfo1 oInfo = new TSysInfo1(b.CommandArgument);
                oInfo.Select();
                typeid.Text = oInfo.TypeID;
                typename.Text = oInfo.TypeName;
                if (oInfo.IsShow == "Y")
                {
                    isshow.Checked = true;
                }
                else
                {
                    isshow.Checked = false;
                }
                orderby.Text = System.Convert.ToString(oInfo.OrderBy);
                msg.Text = "*";
                break;
            case "remove":
                TSysInfo1.DeleteByID(b.CommandArgument);
                ListInfo1();
                break;
        }
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        TSysInfo1 oInfo = new TSysInfo1();
        if (oInfo.FindKey("typeid", typeid.Text))
        {
            msg.Text = "重复";
        }
        else
        {
            oInfo.TypeID = typeid.Text;
            oInfo.TypeName = typename.Text;
            oInfo.TypeClass = "SYS";
            oInfo.Description = "";
            if (isshow.Checked)
            {
                oInfo.IsShow = "Y";
            }
            else
            {
                oInfo.IsShow = "N";
            }
            oInfo.OrderBy = System.Convert.ToDecimal(orderby.Text);
            oInfo.Insert();
            //刷新
            ListInfo1();
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        TSysInfo1 oInfo = new TSysInfo1(typeid.Text);
        oInfo.TypeName = typename.Text;
        oInfo.Description = "";
        if (isshow.Checked)
        {
            oInfo.IsShow = "Y";
        }
        else
        {
            oInfo.IsShow = "N";
        }
        oInfo.OrderBy = System.Convert.ToDecimal(orderby.Text);
        oInfo.Update();
        msg.Text = "*";
        //刷新
        ListInfo1();
    }
}
